#
# MIT License
#
# Copyright (c) 2023 北京凯特伟业科技有限公司
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

#dockerfile用于构建docker镜像
# 基础镜像
FROM java:8
# 作者
MAINTAINER liulijun
LABEL appName=service application=jecloud
# 设置变量
ARG APP_APPLICATION=jecloud
ARG APP_JAR=jeapp.jar
ARG APP_NAME=finance
ARG APP_PORT=8075
ARG AGENT_SERVER_IP
ARG AGENT_SERVER_PORT=11800
# 设置环境变量
ENV SW_AGENT_NAMESPACE ${APP_APPLICATION}
ENV SW_AGENT_NAME ${APP_NAME}
ENV SW_AGENT_COLLECTOR_BACKEND_SERVICES ${AGENT_SERVER_IP}:${AGENT_SERVER_PORT}
ENV SW_TOOLKIT_LOG_GRPC_IP ${AGENT_SERVER_IP}
ENV SW_TOOLKIT_LOG_GRPC_PORT ${AGENT_SERVER_PORT}
ENV SW_LOGGING_FILE_NAME /data/logs/agent/skywalking-api.log
ENV SW_LOGGING_DIR /data/logs/agent
# 创建存放程序的目录
RUN mkdir -p /opt/jecloud
# 创建agent目录
RUN mkdir /opt/jecloud/agent
# 设置开放端口号
EXPOSE ${APP_PORT}
# 移动agent内容至目标文件夹
ADD ./agent/.* /opt/jecloud/agent/
# 设置日志目录映射
VOLUME ["/data/logs/app","/data/logs/agent"]
# 设置工作目录
WORKDIR /opt/jecloud
#拷贝jar到指定目录
COPY ${APP_JAR} /opt/jecloud/jeapp.jar
# 启动容器执行命令
ENTRYPOINT ["java","-javaagent:/opt/jecloud/agent/skywalking-agent.jar","-Djava.security.egd=file:/dev/./urandom","-jar","/opt/jecloud/jeapp.jar"]